<template>
  <div id="app">
    <!-- 导航部分 -->
    <Topbar :key="topBarKey"></Topbar>
    <!-- to -->
    <Header></Header>
    <router-view  @updateKey='updateKeyFn'/>
    <Footer></Footer>
    <!-- 登录 -->
    <Login v-show="isShowLoginModal"></Login>
    <!-- 弹框组件 -->
    <!-- 过渡效果 -->
    <transition name="slide">
      <Toast v-show="isShowToast"></Toast>
    </transition>
  </div>
</template>
<script>
import Topbar from "@/components/Topbar";
import Header from "@/components/Header";
import Footer from "@/components/Footer";
import Login from "@/components/Login";
import Toast from "@/components/Toast";
import { JingpinAPI, ReMenAPI } from "@/request/api.js";
import { mapState } from "vuex";
export default {
  data(){
    return{
      topBarKey:0
    }
  },
  watch: {
    //监听路由地址变化
    "$route.path": {
      handler(newVal, oldVal) {
        if (newVal != oldVal) {
          console.log("*********key变化了");
          //通过改变key 让topbar重载.（组件重载）
          this.topBarKey++;
        }
      },
    },
  },
  methods:{
    updateKeyFn(){
      console.log('key变化了');
      this.topBarKey++;
    }
  },
  computed: {
    ...mapState({
      isShowLoginModal: (state) => state.showModal.isShowLoginModal,
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  components: {
    Topbar,
    Header,
    Footer,
    Login,
    Toast,
  },
  async created() {
    console.log("环境变量值：",process.env.VUE_APP_BASE_URL);
    console.log("环境变量值：",process.env.VUE_APP_STATE_URL);
    // axios.get("/products/recommend").then(res=>{
    //   console.log(res);
    // })
    // JingpinAPI().then(res=>{
    //   console.log(res);
    // }),
    //  ReMenAPI().then(res=>{
    //   console.log(res);
    // })
    let res1 = await JingpinAPI();
    console.log("res1:", res1);
    let res2 = await ReMenAPI();
    console.log("res2:", res2);
  },
};
</script>
<style lang="less">
/* 入场的起始状态 = 离场的结束状态 */
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.3s linear;
}

.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
